﻿using System;
using System.IO;

namespace config.service
{
    /// <summary>
    /// FFB协议接口 - 用于构造函数注入
    /// </summary>
    public interface IFFBProtocol
    {
        // 事件
        event Action<FFBProtocolParser.ProtocolFrame> OnFrameReceived;
        event Action<FFBProtocolParser.DeviceInfo> OnDeviceInfoReceived;
        event Action<FFBProtocolParser.FFBErrorCode> OnOperationResult;
        event Action<string> OnError;

        // 数据接收方法
        void ProcessStreamData(MemoryStream stream);
        void ProcessByteData(byte[] data, int offset, int length);

        // 命令创建方法
        //static byte[] CreateCommandFrame(FFBProtocolParser.FFBCommand command, byte[] data = null);

        // 状态管理
        void ClearBuffer();
    }

    // 枚举定义（放在接口同一命名空间）
    public enum FFBCommand : byte
    {
        CMD_RESET_DEVICE = 0x01,
        CMD_GET_DEVICE_INFO = 0x02,
        CMD_DEVICE_INFO_RESP = 0x03,
        CMD_SAVE_PARAMS = 0x04,
        CMD_OPERATION_RESULT = 0x05,
        CMD_GET_ALL_PARAMS = 0x10,
        CMD_PARAMS_RESP = 0x11,
        CMD_SET_SPRING_PARAMS = 0x12,
        CMD_SET_DAMPER_PARAMS = 0x13,
        CMD_PLAY_TEST_EFFECT = 0x30,
        CMD_STOP_ALL_EFFECTS = 0x31,
        CMD_REALTIME_FORCE = 0x32,
        CMD_EFFECT_STATUS = 0x33,
        CMD_ENABLE_DATA_STREAM = 0x50,
        CMD_DISABLE_DATA_STREAM = 0x51,
        CMD_POSITION_DATA = 0x52,
        CMD_FORCE_OUTPUT_DATA = 0x53,
        CMD_DEVICE_STATUS = 0x54
    }

    public enum FFBErrorCode : byte
    {
        ERR_SUCCESS = 0x00,
        ERR_INVALID_CMD = 0x01,
        ERR_INVALID_DATA = 0x02,
        ERR_DEVICE_BUSY = 0x03,
        ERR_FLASH_WRITE = 0x04
    }

    [Flags]
    public enum DataStreamType : byte
    {
        DATA_STREAM_NONE = 0,
        DATA_STREAM_POSITION = 1,
        DATA_STREAM_FORCE = 2,
        DATA_STREAM_STATUS = 4,
        DATA_STREAM_ALL = 7
    }
}